package com.litq.education.controller;

import com.litq.education.bean.UserTable;
import com.litq.education.service.UserService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.Map;

/**
 * UserController
 *
 * @author Litq
 * @version v1.0
 * @since 2019/2/10 1:30
 */
@RestController
public class UserController {
    Logger logger = LoggerFactory.getLogger(UserController.class);
    @Resource
    private UserService userService;


    /**
     * @Method 登录方法
     * @Author Litq
     * @Version 1.0
     * @Description 判断登录
     * @since 2019/8/15
     */

    @ResponseBody
    @RequestMapping(value = "/doLogin", method = {RequestMethod.POST})
    public Object doLogin(@RequestBody Map<String, Object> reqMap) {
        logger.info("登录信息打印----------------------------------reqMap" + reqMap);
        String name = reqMap.get("name").toString();
        String password = reqMap.get("password").toString();
        logger.info("----------------------------------用户名：" + name);
        logger.info("----------------------------------密码：" + password);
        UserTable user = userService.doLogin(name, password);
        logger.info("----------------------------------返回结果打印：" + user);
        if (user == null) {
            return 1;
        }
        return user;
    }

    /**
     * @Method 登录之前查询方法
     * @Author Litq
     * @Version 1.0
     * @Description 判断用户是否存在
     * @since 2019/8/15
     */
    @ResponseBody
    @RequestMapping(value = "/loginQuery", method = {RequestMethod.POST})
    public Object loginQuery(@RequestBody Map<String, Object> reqMap) {
        logger.info("查询信息打印----------------------------------reqMap" + reqMap);
        String name = reqMap.get("name").toString();
        logger.info("----------------------------------用户名：" + name);
        UserTable user = userService.loginQuery(name);
        logger.info("----------------------------------返回结果打印：" + user);
        if (user == null) {
            return 1;
        }
        return user;
    }

    /**
     * @Method 注册方法
     * @Author Litq
     * @Version 1.0
     * @Description 注册用户
     * @since 2019/8/16
     */
    @ResponseBody
    @RequestMapping(value = "/res", method = {RequestMethod.POST})
    public int res(@RequestBody Map<String, Object> reqMap) {
        logger.info("注册信息打印----------------------------------reqMap" + reqMap);
        int sign = userService.res(reqMap);
        logger.info("注册信息是否成功----------------------------------sign" + sign);
        return sign;
    }


}
